Ones And Zeros 2
Memory limit: 64 MB
Certain positive integers have their decimal representation consisting only of
ones and zeros, and having at least one digit one, e.g. 101. If a
positive integer has not such a property, one can try to multiply it by some
positive integer to find out whether the product has this property.
Task
Write a program which:
- reads from the standard input positive integers not greater
than ,
- for each integer read computes the correct answer,
- writes the answer to the standard output.
The answer is either the smallest positive multiple of
whose decimal
representation consists only of zeros
or ones, or the word
BRAK (Polish for
absence), if there is no such
multiple.
Input
The standard input contains in the first line a positive integer .
In consecutive lines there is a sequence of numbers in
the range of [], one number per line. The numbers
in the standard input are written correctly, and your program need not verify
that.
Output
Each line of the standard output, starting with the first, should contain:
- either only one word BRAK,
- or exactly one positive integer being a multiple of a successive number
given in the input; each multiple must be a number composed only of digits
and , and has to be written with no spaces between the
digits.
The answers are to be written in standard output in the same order as the
corresponding numbers in standard input.
Example
For the input data:
6
17
11011
17
999
125
173
the correct result is:
11101
11011
11101
111111111111111111111111111
1000
1011001101
Task author: Andrzej Walat.